从给定的文字内容中 解析Email地址, 并显示出来. 同时支持QQ提取.
原理与代码:
Update: 正则表达式已更正, 参考: http://liguoliang.com/2011/validate-email-regex/
Flex使用正则表达式搜索内容
核心代码:
/** 当按下解析按钮时响应. */ protected function onButtonParse(event:MouseEvent):void { var sourceStr:String = StringUtils.trim(textSource.text); var resultMap:Object = new Object(); if(StringUtils.isEmptyString(sourceStr)) { Alert.show("请先输入要解析的字符"); return; } textOutput.text = ""; var patternEmail:RegExp = new RegExp("(([\\w\\.-]{1,})@([\\w-]{1,}\\.+[a-zA-Z]{2,}))", "g"); var resultsRawEmail:Array = sourceStr.match(patternEmail); for each(var resultEmail:String in resultsRawEmail) { resultMap[resultEmail] = resultEmail; } if(checkBoxQQ.selected) { TextAreaUtils.appendMessageAndScrollProperly(textOutput, "本次解析会自动解析QQ号码, 并追加@qq.com"); var patternQQ:RegExp = new RegExp("([1-9][\\d]{4,})", "g"); var resultsRawQQ:Array = sourceStr.match(patternQQ); for each(var result:String in resultsRawQQ) { resultMap[result+ "@qq.com"] = result + "@qq.com"; } } TextAreaUtils.appendMessageAndScrollProperly(textOutput, "解析完毕, 共获得: " + ObjectUtils.getSize(resultMap)); for(var key:String in resultMap) { TextAreaUtils.appendMessageAndScrollProperly(textOutput, resultMap[key] + ", ", false); } } /** 当Linkbutton点击时响应. */ protected function onLinkbuttonClick(event:MouseEvent):void { navigateToURL(new URLRequest("http://liguoliang.com")); }
新疆大学行政管理考研真题04,05,06 & 08下载 <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.